<template>
	<el-container>
		<el-aside width="200px" v-loading="showGrouploading">
			<el-container>
				<el-header>
					<el-input placeholder="输入关键字进行过滤" v-model="groupFilterText" clearable></el-input>
				</el-header>
				<el-main class="nopadding">
					<el-tree ref="group" class="menu" node-key="deptId" :data="group" :props="groupsProps" :current-node-key="''" :highlight-current="true" :expand-on-click-node="false" :filter-node-method="groupFilterNode" @node-click="groupClick"></el-tree>
				</el-main>
			</el-container>
		</el-aside>
		<el-container>
			<el-header>
				<div class="left-panel">
				</div>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.keyword" placeholder="账号 / 别名 / 姓名 / 电话 / 拼音" clearable></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" stripe remoteSort remoteFilter>
					<el-table-column label="#" type="index" width="50"></el-table-column>
					<el-table-column label="头像" width="80">
						<template #default="scope">
							<el-avatar :src="scope.row.avatar" size="small"></el-avatar>
						</template>
					</el-table-column>
					<el-table-column label="登录账号" prop="accountId" width="150" sortable='custom'></el-table-column>
					<el-table-column label="姓名" prop="userName" width="100" sortable='custom'></el-table-column>
					<el-table-column label="别名" prop="alias" width="100" sortable='custom'></el-table-column>
					<el-table-column label="拼音" prop="pinYin" width="120" sortable='custom'></el-table-column>
					<el-table-column label="性别" prop="sex" width="60">
						<template #default="scope">
							<el-button type="primary" size="small" v-if="scope.row.sex==='1'">男</el-button>
							<el-button type="danger" size="small" v-else-if="scope.row.sex==='0'">女</el-button>
							<el-button type="info" size="small" v-else>保密</el-button>
						</template>
					</el-table-column>
					<el-table-column label="行政级别" prop="levelName" width="100"></el-table-column>
					<el-table-column label="联系电话" prop="phone" width="150">
						<template #default="scope">
							{{tool.crypto.convertData(scope.row.phone)}}
						</template>
					</el-table-column>
					<el-table-column label="状态" prop="status" width="100">
						<template #default="scope">
							<el-tag v-if="scope.row.wxAccountId==''||scope.row.wxAccountId==undefined" type="danger">未绑定</el-tag>
							<el-tag  v-else type="success">已绑定</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="微信账号" prop="wxAccountId" width="150"></el-table-column>
					<el-table-column label="人员来源" prop="isIn" width="100">
						<template #default="scope">
							<el-button type="warning" size="small" round v-if="scope.row.isIn==='1'">外部</el-button>
							<el-button type="success" size="small" round v-else-if="scope.row.isIn==='0'">内部</el-button>
							<el-button type="info" size="small" round v-else>未知</el-button>
						</template>
					</el-table-column>
					<el-table-column label="操作" fixed="right" align="right" width="100">
						<template #default="scope">
							<el-button-group>
								<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)" v-if="scope.row.wxAccountId==''||scope.row.wxAccountId==undefined">同步</el-button>
								<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)" v-else>解绑</el-button>
							</el-button-group>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
</template>

<script>
import tool from "../../../utils/tool";
export default {
	name: 'Sync WeiXin Account',
	computed: {
		tool() {
			return tool
		}
	},
	components: {
	},
	data() {
		return {
			dialog: {
				save: false
			},
			resetPwd:{
				save: false
			},
			userbase:{
				save: false
			},
			showGrouploading: false,
			groupFilterText: '',
			group: [],
			groupsProps: {
				label:"deptName",
				value: "deptId"
			},
			apiObj: this.$API.system.user.list,
			search: {
				keyword: null
			}
		}
	},
	watch: {
		groupFilterText(val) {
			this.$refs.group.filter(val);
		}
	},
	mounted() {
		this.getDeptGroup()
	},
	methods: {
		//编辑
		async table_edit(row){
			var res = await this.$API.system.user.syncWeiXinAccount.post({accountId:row.accountId});
			if (res.code == 200) {
				this.$message.success("操作成功");
				this.$refs.table.refresh();
			}else
			{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//加载树数据
		async getDeptGroup(){
			this.showGrouploading = true;
			var res = await this.$API.system.unitDept.list.get();
			this.showGrouploading = false;
			var allNode ={deptId: '', deptName: '所有'}
			res.data.unshift(allNode);
			this.group = res.data;
		},
		//树过滤
		groupFilterNode(value, data){
			if (!value) return true;
			return data.deptName.indexOf(value) !== -1;
		},
		//树点击事件
		groupClick(data){
			var params = {
				deptId: data.deptId
			}
			this.$refs.table.reload(params)
		},
		//搜索
		upsearch(){
			this.$refs.table.upData(this.search)
		},
	}
}
</script>

<style>
</style>
